
import java.util.Scanner;
import java.util.Arrays;


/*class robot{
    //成员属性
    public String colour;
    public double height;
    public double weight;
    //...
    //行为
    public void fun1(){
        System.out.println("与人沟通");
    }
    public void fun2(){
        System.out.println("做饭");
    }
    public void fun3(){
        System.out.println("洗衣服");
    }
}*/
class student{
    //成员变量
    private String name;
    public int age;
}
public class Test{
    public static void main(String[] args){

    }
/*    public static void main20(String[] args){
        robot machine1 = new robot();
        machine1.colour = "蓝色";
        machine1.height = 1.88;
        machine1.weight = 300.25;
        machine1.fun1();
    }*/
    public static void main19(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};
        //1
        for(int i = 0; i < array.length; i++){
            for(int j = 0; j < array[i].length; j++){
                System.out.print(array[i][j] + " ");
            }
        }
        System.out.println();
        //2
        for(int[] tmp : array){
            for(int x : tmp){
                System.out.print(x + " ");
            }
        }
        System.out.println();
        //3
        System.out.println(Arrays.deepToString(array));
    }
    //模拟
    public static String myToString(int[] array){
        String str = "[ ";
        for(int i = 0; i < array.length; i++){
            str += array[i];
            if(i !=array.length - 1){
                str += ", ";
            }
        }
        str += "]";
        return str;
    }
    public static void main18(String[] args){
        int[] array = {1,2,3,4,5};
        String str = myToString(array);
        System.out.println(str);
    }
    //二分法
    public static int sort(int[] array, int k){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(k < array[mid]){
                right = mid - 1;
            }
            else if(k == array[mid]){
                return mid;
            }
            else{
                left = mid + 1;
            }
        }
        return -1;
    }
    public static void main17(String[] args){
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int key = 6;
        int ret = sort(array, key);
        if(ret != -1){
            System.out.println("找到了，下标是:" + ret);
        }
        else{
            System.out.println("没找到");
        }
    }
    //给定一个整型数组, 判定数组是否有序（递增）
    public static void main16(String[] args){
        int[] array = {1,2,3,9,5};
        for(int i = 0; i < array.length - 1; i++){
            if(array[i] > array[i + 1]){
                System.out.println("no");
                return;
            }
        }
        System.out.println("yes");
    }
    //给定一个整型数组, 实现冒泡排序(升序排序)
    public static void bubbleSort(int[] array){
        for(int i = 0; i < array.length - 1; i++){
            boolean flag = false;
            for(int j = 0; j < array.length - i - 1; j++){
                if(array[j] > array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flag = true;
                }
            }
            if(flag == false){
                break;
            }
        }
    }
     public static void main15(String[] args){
         int[] array = {1,8,4,3,9,4,6,2};
         bubbleSort(array);
         System.out.println(Arrays.toString(array));
     }
    /**
     * 给定一个整数数组 nums 和一个整数目标值 target，请你在该数组中找出 和为目标值 target 的那 两个 整数，并返回它们的数组下标。
     * 你可以假设每种输入只会对应一个答案。但是，数组中同一个元素在答案里不能重复出现。
     * 你可以按任意顺序返回答案。
     * 示例 1：
     * 输入：nums = [2,7,11,15], target = 9
     * 输出：[0,1]
     * 解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1] 。
     * @param args
     */
    public static void main14(String[] args){
        int[] nums = {2,7,11,15};
        int[] num = new int[2];
        int target = 9;
        for(int i = 0; i < nums.length; i++){
            for(int j = 0; j < nums.length; j++){
                if(nums[i] + nums[j] == target){
                    num[0] = i;
                    num[1] = j;
                    System.out.println(Arrays.toString(num));
                    return;
                }
            }
        }
        System.out.println("找不到~");
    }
    //创建一个 int 类型的数组, 元素个数为 100, 并把每个元素依次设置为 1 - 100
    public static void main13(String[] args){
        int[] array = new int[100];
        for(int i = 0; i < 100; i++){
            array[i] = i + 1;
        }
        System.out.print(Arrays.toString(array));
    }
    //数组整体*2
    public static void main12(String[] args){
        int[] array = {1,2,3};
        for(int i = 0; i < array.length; i++){
            array[i] = array[i] * 2;
        }
        System.out.println(Arrays.toString(array));
    }
    //递归求 N 的阶乘
    public static int sum3(int n){
        if(n == 1){
            return 1;
        }
        else{
            return n * sum3(n - 1);// 4 * 3 * 2 * 1
        }
    }
    public static void main11(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = sum3(n);
        System.out.println(ret);
    }
    //递归求 1 + 2 + 3 + ... + 10
    public static int sum2(int n){
        if(n == 1){
            return 1;
        }
        else
        {
            return n + sum2(n - 1);
        }
    }
    public static void main10(String[] args){
        int n = 10;
        int ret = sum2(n);
        System.out.println(ret);
    }
    //按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4) （递归）
    public static void print(int n){
        if(n < 10){
            System.out.print(n % 10 + " ");
        }
        else{
            print(n / 10);
            System.out.print(n % 10 + " ");
        }
    }
    public static void main9(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        print(n);
    }
    //求斐波那契数列的第n项。(迭代实现)
    public static void main8(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 0;
        int count = 0;
        int obj = 1;
        int tmp = 1;
        while(count <= n){
            if(count <= 2){
                sum = 1;
            }
            else{
                sum += obj;
                obj = tmp;
                tmp = sum;
            }
            count++;
        }
        System.out.println(sum);

    }
    //写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int sum(int n){
        if(n < 10){
            return n % 10;
        }
        else
        {
            return n % 10 + sum(n / 10);
        }

    }
    public static void main7(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = sum(n);
        System.out.println(ret);
    }
    //求斐波那契数列的第n项。(迭代实现)1 1 2 3 5 8
    public static int fac(int n){
        if(n <= 2){
            return 1;
        }
        else{
            return fac(n - 1) + fac(n - 2);
        }
    }
    public static void main6(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = fac(n);
        System.out.println(ret);
    }
    //数组比较
    public static void main5(String[] args){
        int[] array1 = new int[]{1,2,3,4,5};
        int[] array2 = new int[]{1,2,3,4,5};
        boolean flag = Arrays.equals(array1,array2);
        System.out.println(flag);
    }
    //指定拷贝
    public static void main4(String[] args){
        int[] array = new int[]{1,2,3,4,5};
        int[] arrayCopy = Arrays.copyOfRange(array, 0,3);
        System.out.println(Arrays.toString(arrayCopy));
    }
    //排序实例
    public static void main3(String[] args){
        int[] array = new int[]{5,3,2,6,1,9};
        Arrays.sort(array,1, 4);
        System.out.println(Arrays.toString(array));
    }
    //字符串打印数组实例
    public static void main2(String[] args){
        int[]array = new int[]{1,2,3,4,5};
        System.out.println(Arrays.toString(array));
    }
    //数组拷贝
    public static void main1(String[] args){
        int[] array = {1,2,3,4,5};
        int[] copy = Arrays.copyOf(array, array.length*2);
        for(int i = 0; i < copy.length; i++){
            System.out.print(copy[i] + " ");
        }
    }
}
